﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Avenger;
using SharpICTCLAS;

namespace IronMan
{
    public partial class Form1 : Form
    {
        public List<Tweet> TweetList;
        public Dictionary<string, long> dictionary;
        private string DictPath = Path.Combine(Environment.CurrentDirectory, "Data") + Path.DirectorySeparatorChar;
        private WordSegment wordSegment;
        public Form1()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MySqlManager.Instance.connectMySqlServer();
            MySqlManager.Instance.useAvenger();
            MySqlManager.Instance.getAllTweet(out TweetList);
            foreach (Tweet tweet in TweetList)
            {
                List<WordResult[]> results = segment(Microsoft.VisualBasic.Strings.StrConv(tweet.text,Microsoft.VisualBasic.VbStrConv.SimplifiedChinese));
                //if (results.Count > 2)
                //{
                //    for (int i = 1; i < results.Count - 1; ++i)
                //    {
                //        MessageBox.Show(results[0][i].sWord + results[0][i].nPOS.ToString());
                //    }
                //}
            }
        }
        private List<WordResult[]> segment(string Segment)
        {
            if (wordSegment == null)
            {
                wordSegment = new WordSegment();
                wordSegment.InitWordSegment(DictPath);
            }
            return wordSegment.Segment(Segment);
        }
    }
}
